package Algorithm.LengthOfLongestSubstring;

import java.util.HashSet;

public class LengthOfLongestSubstring {

    public int lengthOfLongestSubstring(String s) {
        if (s.length() == 0 || s == null) {
            return 0;
        }
        int res = 0;
        for (int l = 0; l < s.length(); l++) {
            for (int r = 1; r < s.length(); r++) {
                if (isUnique(s,l,r)){
                    res = Math.max(res, r - l + 1);
                }
            }
        }
        return res;
    }



    public  boolean isUnique(String s,int L,int R){
        HashSet<Character> set = new HashSet<>();
        for (int i = L; i <= R; i++) {
            if (!set.contains(s.charAt(i))) {
                set.add(s.charAt(i));
            }else{
                return false;
            }
        }
        return true;
    }
}
